package com.itjob.scott.student.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.itjob.scott.student.dao.StudentDao;
import com.itjob.scott.student.entity.StudentEntity;
import com.itjob.scott.student.service.StudentService;

@Service
public class StudentServiceImpl implements StudentService {

	@Resource
	private StudentDao dao;
	
	public boolean loginValidate(StudentEntity entity) {
		
		return dao.queryStudentByUsernameAndPassword(entity) == 1?true:false;
	}

	public boolean checkDouble(String username) {
		//1表示重复
		return dao.queryStudentByUsername(username) == 1?true:false;
	}

	//@Transactional(propagation=Propagation.REQUIRED)
	public void save(StudentEntity entity) {
		int id = dao.getNewStudentId();
		entity.setId(id);
		
		//插入数据到学生表
		dao.insertStudentEntity(entity);
		
		//插入数据到关系表
		dao.insertStudentAndLanguageRelationship(entity);
	}

}
